import cursor
import pymysql

with open('ur.txt', 'r', encoding='utf-8') as r:
    data=r.readlines()
for j in data:
    k=str(j).split("rating")
    for i in k:
        try:
            title =""
            score=""
            date=""
            poster=""
            suppliers=""
            regions=""
            type=""
            summery=""
            title=i.split("title':'")[1].split("','url':")[0]
            score=i.split("score':'")[1].split("','suppliers")[0]
            date=i.split("release_date':'")[1].split("','suppliers_count")[0]
            poster=i.split("cover_url':'")[1].split("','is_pla")[0]
            suppliers=i.split("suppliers':'")[1].split("','is_watched")[0].replace("','","").replace("['","")
            regions=i.split("regions':['")[1].split("'],'title")[0].replace("','","")
            type=i.split("types':['")[1].split("'],'regions")[0].replace("','","")
            summery=i.split("types:':['")[1].split("'],'regions")[0].replace("','","")
            coon=pymysql.connect(host='localhost',user='rjxy',password='1234',db='djago_taobao')
            cur=coon.cursor()
            sql = "INSERT INTO myapp_goods (title, score, date, poster, suppliers, regions, type, summery) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
            cursor.execute(sql, (title, score, date, poster, suppliers, regions, type, summery))
            cur.execute(sql)
            coon.commit()
            cur.commit()
            coon.close()
        except:
            continue